home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-03-01 | 2.5 KB | 130 lines | [TEXT/CWIE] |
- //
- // C3DMFReader.cp
- //
- // A class for building a Display TQ3GroupObject
- //
- // by James Jennings
- // February 28, 1997
- //
-
- #include "C3DMFReader.h"
- #include "CShaderMakers.h"
- #include "StQ3Disposer.h"
-
- #pragma mark === StObjectReader ===
- // StObjectReader wraps the reading of files from a TQ3ObjectFile
- class StObjectReader : public CObjectMaker<TQ3Object> {
- public:
- virtual void ReadObjectFrom(TQ3FileObject inFile);
-
- virtual Boolean IsNull() { return mObject==nil; }
- virtual Boolean IsViewHints();
- virtual Boolean IsDrawable();
-
- protected:
- virtual void Make() { Assert_(false /* Make() should never be called */); }
- };
-
- void StObjectReader::ReadObjectFrom(TQ3FileObject inFile)
- {
- Assert_(inFile != nil);
- Q3Forget(mObject);
- mObject = ::Q3File_ReadObject(inFile);
- }
-
- Boolean StObjectReader::IsViewHints()
- {
- Assert_(mObject!=nil);
- return ::Q3Object_IsType(mObject, kQ3SharedTypeViewHints) == kQ3True;
- }
-
- Boolean StObjectReader::IsDrawable()
- {
- Assert_(mObject!=nil);
- return ::Q3Object_IsDrawable(mObject) == kQ3True;
- }
-
-
- #pragma mark === C3DMFReader ===
-
- C3DMFReader::C3DMFReader(FSSpec *inFSSpec)
- : mViewHints(0), mFile(0)
- {
- Assert_(inFSSpec != nil);
- TQ3Status theStatus;
- TQ3StorageObject theStorage;
-
- try{
-
- theStorage = ::Q3FSSpecStorage_New(inFSSpec);
- ThrowIfNil_(theStorage);
-
- mFile = ::Q3File_New();
- ThrowIfNil_(mFile);
-
- theStatus = ::Q3File_SetStorage(mFile, theStorage);
- ThrowIfQ3Fail_(theStatus);
- Q3Forget(theStorage);
-
- }
- catch(...) {
- Q3Forget(mFile);
- Q3Forget(theStorage);
- throw;
- }
- }
-
- C3DMFReader::~C3DMFReader()
- {
- Q3Forget(mViewHints);
- Q3Forget(mFile);
- }
-
- TQ3GroupPosition C3DMFReader::Add( TQ3GeometryObject inObject )
- {
- Assert_( mObject != nil );
-
- TQ3GroupPosition pos;
-
- pos = ::Q3Group_AddObject( mObject, inObject );
- ThrowIf_(pos==0);
-
- return pos;
- }
-
- void C3DMFReader::Make()
- {
- TQ3Status theStatus;
-
- mObject = ::Q3DisplayGroup_New();
- ThrowIfNil_( mObject );
-
- // Add a shader.
- CPhongShaderMaker shader;
- Add(shader.Get());
-
- theStatus = ::Q3File_OpenRead(mFile,nil);
- ThrowIfQ3Fail_(theStatus);
-
- StObjectReader theObject;
-
- while (::Q3File_IsEndOfFile(mFile) == kQ3False) {
-
- theObject.ReadObjectFrom( mFile );
- if (theObject.IsNull()) continue;
-
- if ( theObject.IsViewHints() && mViewHints == nil )
- mViewHints = theObject.GetRef();
-
- if (theObject.IsDrawable())
- Add(theObject.Get());
-
- }
-
- // The file will be closed automatically when mFile is disposed
- // but it's nice to be explicit about it.
- theStatus = ::Q3File_Close(mFile);
- ThrowIfQ3Fail_(theStatus);
- }
-
-